﻿///////////////////////////////////////////////////////////////////////////
//投票调查扩展插件
///////////////////////////////////////////////////////////////////////////
function ajaxPluginVote(oDiv, save2file)
{
	if(PluginVote==null)
	{
		$("#"+oDiv).hide();
		return;
	}
	if(oDiv==null) oDiv="ajaxPluginVote";
	if(save2file=="js")
		ExecuteTemplate($$_JSON_PluginVote, site.Dir + "extends/vote/templates/_vote.htm", oDiv, site.Dir + "_data/style/p_vote.js", "Vote", "js");
	else if(save2file=="html")
		ExecuteTemplate($$_JSON_PluginVote, site.Dir + "extends/vote/templates/_vote.htm", oDiv, site.Dir + "_data/html/p_vote.htm", "Vote", "html");
	else
		ExecuteTemplate($$_JSON_PluginVote, site.Dir + "extends/vote/templates/_vote.htm", oDiv);
}
function ajaxPluginVoteAdd(id,mtype,btn)
{
	btn="#"+btn;
	$(btn).attr("disabled","disabled");
	var voteNum;
	var rbVote=$("#voteform input");
	for(var i=0;i<rbVote.length;i++)
	{
		if(rbVote[i].checked && (rbVote[i].type=="radio" || rbVote[i].type=="checkbox")){
			if(!voteNum)
				voteNum=rbVote[i].value;
			else
				voteNum += "," + rbVote[i].value;
		}
	}
	if(!voteNum){
		alert("请先选择一项!");
		$(btn).attr("disabled","");
		return;
	}
	$.ajax({
		type:		"get",
		dataType:	"html",
		data:		"id="+id+"&mtype="+mtype+"&vote="+voteNum+"&time="+(new Date().getTime()),
		url:		site.Dir + "extends/vote/ajax.aspx?oper=ajaxPluginVoteAdd",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			if(d=="ok")
			{
				alert("成功,谢谢你的投票!");
			}
			else
			{
				alert(d);
				$(btn).attr("disabled","");
			}
		}
	});
}